package Ui;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Point;
import java.awt.Toolkit;

import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.SwingUtilities;
/*
 * @author Paolo Cordova
 */
public class DisplayAssembler 
{

	private static DisplayAssembler INSTANCE;
	private JDesktopPane desktopPane_ = null;
	
	private static int rightEdge_;
	private static int boxSize_, spaceWidth_, topLeftGo_;
	
	private static Dimension screen_;
	
	private DisplayAssembler()
	{
		 screen_ = Toolkit.getDefaultToolkit().getScreenSize();
	}

	public static DisplayAssembler getInstance() 
	{
		if(INSTANCE == null) 
			INSTANCE = new DisplayAssembler();
		
		return INSTANCE;
	}
	
	public void setRightEdge(int rightEdge) 
	{
		rightEdge_ = rightEdge;
	}
	
	public void setBoxSize(int boxSize) 
	{
		boxSize_ = boxSize;
	}
	
	public void setSpaceWidth(int spaceWidth)
	{
		spaceWidth_ = spaceWidth;
	}
	
	public void setTopLeftGo(int topLeftGo) 
	{
		topLeftGo_ = topLeftGo;
	}
	
	public static int getRightEdge()
	{
		return rightEdge_;
	}
	
	public static int getBoxSize()
	{
		return boxSize_;
	}
	
	public static int getSpaceWidth()
	{
		return spaceWidth_;
	}
	
	public static int getTopLeftGo()
	{
		return topLeftGo_;
	}
	
	public void setDesktopPane(JDesktopPane desktopPane)
	{
		desktopPane_ = desktopPane;
	}
	
	public void addComponent(JComponent component, Point location, Object layer)
	{
		component.setLocation(location);
		desktopPane_.add(component, layer);
	}
	
	public void addComponent(JComponent component, int pointX, int pointY, Object layer)
	{
		component.setLocation(pointX, pointY);
		desktopPane_.add(component, layer);
	}
	
	public void animateComponentLocation(final JComponent component, final int pointX, final int pointY)
	{
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				component.setLocation(pointX, pointY);
			}
		});
	}
	
	public void removeComponent(JComponent component)
	{
		desktopPane_.remove(component);
	}
	
	public static int getScreenHeight() 
	{
		return screen_.height;
	}
	
	public static int getScreenWidth() 
	{
		return screen_.width;
	}
	
	public FontMetrics getFontMetrics(Font font) 
	{
		return desktopPane_.getFontMetrics(font);
	}
}
